package com.tg.paw.common.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Rubble
 * Created on 2020/4/5
 */
public class NameUtil {

    private static Pattern linePattern = Pattern.compile("_(\\w)");
    /** 下划线转驼峰 */
    public static String lineToHump(String name) {
        name = name.toLowerCase();
        Matcher matcher = linePattern.matcher(name);
        StringBuffer sb = new StringBuffer();
        while (matcher.find()) {
            matcher.appendReplacement(sb, matcher.group(1).toUpperCase());
        }
        matcher.appendTail(sb);
        return sb.toString();
    }

    /** 驼峰转下划线 */
    public static String humpToLine(String name) {
        return name.replaceAll("[A-Z]", "_$0").toLowerCase();
    }
}
